export default{
	data(){
		const checkApprovalType = (rule, value, callback) => {
			if (value) {
				callback()
			} else {
				callback(new Error('请选择审批结果'))
			}
		}
		const checkApprovalComment = (rule, value, callback) => {
			if (value) {
				callback()
			} else {
				callback(new Error('请输入审批意见'))
			}
		}
		const checkApprovalTargetKey = (rule, value, callback) => {
			if (value) {
				callback()
			} else {
				if (this.approvalForm.type != 2) {
					callback()
				} else {
					callback(new Error('请选择退回节点'))
				}
			}
		}
		return{
			screenHeight: undefined,
			originalHeight: undefined,
			lineCount: 0,
			lineCount2: 0,
			fromTab: 1, //判断是从【待办，已办】哪个tab页面进行的跳转  待办中跳转都能进行审批，已办只能查看详情
			detailId: undefined,
			loading: false,
			formData: {
				reviewCode: '1',
				code: 2,
				name: 3
			}, // 基本信息
			// 合同明细
			listData: null,
			
			// 审批
			approvalForm: {
				type: "1",
				// 审批意见
				comment: '同意',
				// 退回节点key
				targetKey: "",
				// 任务id
				taskId: "",
				// 流程实例id
				instanceId: "",
				// 退回节点名称
				returnNodeName: ""
			},
			showPicker: false,
			returnsList: [],
			rules: {
				type: [{
					required: true,
					message: '请选择审批结果',
					trigger: ['blur', 'change'],
					validator: checkApprovalType
				}],
				comment: [{
					required: true,
					message: '请输入审批意见',
					trigger: ['change'],
					validator: checkApprovalComment
				}],
				targetKey: [{
					required: true,
					message: '请选择退回节点',
					trigger: ['blur', 'change'],
					validator: checkApprovalTargetKey
				}],
			},
			// 退回节点时所用参数
			// 审批记录
			flowList: [],
		}
	},
	mounted() {
		//首次进入的原始高度
		// this.originalHeight = window.innerHeight;
		// window.addEventListener('resize', this.watchResize);
	},
	methods:{
		//实时变化的窗口高度
		watchResize() {
			this.screenHeight = window.innerHeight;
		},
		lineChange(val) {
			this.lineCount = val.detail.lineCount
		},
		lineChange2(val) {
			this.lineCount2 = val.detail.lineCount
		},
		successMethod(msg) {
			uni.showToast({
				title: msg,
				icon: 'none',
				duration: 2000
			})
			setTimeout(() => {
				uni.navigateBack({
					delta: 1
				});
			}, 2000)
		},
		// 通过方法
		confirmComplete() {
			this.$api.postConfirmComplete(this.approvalForm).then((res) => {
				if (res.code === 200) {
					this.successMethod(res.msg)
				}
			});
		},
		// 退回方法
		confirmReturn() {
			this.$api.postConfirmReturn(this.approvalForm).then((res) => {
				if (res.code === 200) {
					this.successMethod(res.msg)
				}
			});
		},
		// 驳回方法
		confirmReject() {
			this.$api.getConfirmReject(this.approvalForm).then((res) => {
				if (res.code === 200) {
					this.successMethod(res.msg)
				}
			});
		}, // 提交审批
		// 提交审批
		submitForm() {
			this.$refs.approvalForm.validate().then(valid => {
				if (valid) {
					switch (this.approvalForm.type) {
						case 1:
						case "1":
							// 通过
							this.confirmComplete();
							break;
						case 2:
						case "2":
							// 退回
							this.confirmReturn();
							break;
						case 3:
						case "3":
							// 驳回
							this.confirmReject();
							break;
		
					}
				}
			})
		},
		// 退回节点选择
		confirmPicker(val) {
			this.approvalForm.returnNodeName = val.value[0].name
			this.approvalForm.targetKey = val.value[0].id
			this.showPicker = false
		},
		// 退回节点列表下拉
		closePicker() {
			this.showPicker = false
		},
		nodeInputHandler() {
			this.showPicker = true
		},
		// 获取可退回节点
		getReturnList() {
			this.$api.getReturnList(this.approvalForm).then(res => {
				this.returnsList = []
				this.returnsList.push(res.data)
			})
		},
		groupChange(val) {
			this.approvalForm.type = val
			this.approvalForm.targetKey = ""
			this.approvalForm.returnNodeName = ""
			if (this.approvalForm.type == 3) {
				this.approvalForm.comment = '驳回'
				this.$refs.approvalForm.validate()
			} else if (this.approvalForm.type == 1) {
				this.approvalForm.comment = '同意'
				this.$refs.approvalForm.validate()
			} else {
				this.approvalForm.comment = ""
				// this.getReturnList()
			}
		},
		// 获取审批记录
		async getApprovalRecords() {
			let param = {
				procInsId: this.formData.procInsId,
				deployId: this.formData.deployId,
			};
			await this.$api.getApprovalRecords(param).then(res => {
				this.flowList = [...res.data.flowList]
				this.flowList = this.flowList.reverse()
				// this.approvalForm.taskId = res.data.flowList[0]?.taskId
				this.approvalForm.instanceId = this.formData.procInsId;
			})
			this.pageLoading = false
		},
	},
	watch: {
		// screenHeight(newHeight) {
		// 	// 解决安卓底部固定部位被软键盘顶上去问题
		// 	//监听屏幕高度变化  
		// 	var f = document.getElementById("fixB")
		// 	if (newHeight < this.originalHeight) {
		// 		f.style.position = 'static';
		// 	} else {
		// 		f.style.position = 'fixed';
		// 	}
		// }
	},
}